import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _class, _class2;

/**
 * PersonalLoginRecord - 个人（登录记录）
 * @date: 2019-01-10
 */
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Bind } from 'lodash-decorators';
import { getCurrentOrganizationId } from 'utils/utils';
import intl from 'utils/intl';
import { Header, Content } from 'components/Page';
import { Table } from 'antd';
import formatterCollections from 'utils/intl/formatterCollections';
var prefix = 'cpfm.login.audit.model';
var PersonalLoginRecord = (_dec = connect(function (_ref) {
  var personalLoginRecord = _ref.personalLoginRecord,
      loading = _ref.loading;
  return {
    personalLoginRecord: personalLoginRecord,
    loading: loading.effects['personalLoginRecord/fetchRecords'],
    tenantId: getCurrentOrganizationId()
  };
}), _dec2 = formatterCollections({
  code: 'cpfm.login'
}), _dec3 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(PersonalLoginRecord, _PureComponent);

  var _super = _createSuper(PersonalLoginRecord);

  function PersonalLoginRecord() {
    _classCallCheck(this, PersonalLoginRecord);

    return _super.apply(this, arguments);
  }

  _createClass(PersonalLoginRecord, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this$props = this.props,
          dispatch = _this$props.dispatch,
          tenantId = _this$props.tenantId;
      var type = 'personalLoginRecord/fetchRecords';
      dispatch({
        type: type,
        payload: {
          tenantId: tenantId
        }
      });
    }
    /**
     * 处理表格翻页
     * @param {*} page
     * @memberof PersonalLoginRecord
     */

  }, {
    key: "onChange",
    value: function onChange(page) {
      var _this$props2 = this.props,
          dispatch = _this$props2.dispatch,
          tenantId = _this$props2.tenantId;
      dispatch({
        type: 'personalLoginRecord/fetchRecords',
        payload: {
          tenantId: tenantId,
          page: _isEmpty(page) ? {} : page
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props3 = this.props,
          loading = _this$props3.loading,
          _this$props3$personal = _this$props3.personalLoginRecord,
          _this$props3$personal2 = _this$props3$personal.dataSource,
          dataSource = _this$props3$personal2 === void 0 ? [] : _this$props3$personal2,
          _this$props3$personal3 = _this$props3$personal.pagination,
          pagination = _this$props3$personal3 === void 0 ? {} : _this$props3$personal3;
      var columns = [{
        title: intl.get("".concat(prefix, ".login.auditTypeMeaning")).d('审计类型'),
        width: 150,
        dataIndex: 'auditTypeMeaning'
      }, {
        title: intl.get("".concat(prefix, ".login.time")).d('登录时间'),
        width: 200,
        dataIndex: 'loginDate'
      }, {
        title: intl.get("".concat(prefix, ".login.address")).d('登录地址'),
        width: 200,
        dataIndex: 'loginIp'
      }, {
        title: intl.get("".concat(prefix, ".login.device")).d('登录设备'),
        dataIndex: 'loginDevice'
      }];
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, {
        title: intl.get('cpfm.userInfo.view.login.log').d('登录日志'),
        backPath: "/ciam/user/info"
      }), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "order",
        loading: loading,
        columns: columns,
        dataSource: dataSource.map(function (item, index) {
          return _objectSpread(_objectSpread({}, item), {}, {
            order: index + 1
          });
        }),
        pagination: pagination,
        onChange: function onChange(page) {
          return _this.onChange(page);
        }
      })));
    }
  }]);

  return PersonalLoginRecord;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "onChange", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "onChange"), _class2.prototype)), _class2)) || _class) || _class);
export { PersonalLoginRecord as default };